from selenium import webdriver
import time
from Page.Page import Page
from Page.Page2 import Page2
from Page.Page3 import Page3
from selenium.webdriver.common.by import By
import unittest
from ddt import ddt, file_data

@ddt()
class TestCase(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Edge()
        self.driver.maximize_window()
        print('case start')

    def tearDown(self):
        time.sleep(5)
        print('case end')
        self.driver.quit()

    @file_data(r'D:\zhuangaoliu\gaoweiyk_ui\Data\ss_name.json')
    def test_user_01(self, name, casename, exp):
        po = Page(self.driver)
        po.open_url('http://localhost:8081/')
        print(casename+exp)
        time.sleep(2)
        po.click_user()
        time.sleep(2)
        dy1 = self.driver.find_element(By.XPATH, '/html/body/div[1]/div/section/section/main/h2').text
        self.assertIn('客户列表', dy1)
        po.click_fenye()
        po.send_name(name)
        po.click_button()
        time.sleep(2)
        dy2 = self.driver.find_element(By.XPATH, '/html/body/div[1]/div/section/section/main/form/div/div[1]/div/label').text
        self.assertEqual('客户名称', dy2)

    def test_user_02(self):
        po = Page2(self.driver)
        po.open_url('http://localhost:8081/')
        time.sleep(2)
        po.click_user()
        time.sleep(2)
        dy1 = self.driver.find_element(By.XPATH, '/html/body/div[1]/div/section/section/main/h2').text
        self.assertIn('客户列表', dy1)
        po.click_fenye()
        po.click_add()
        time.sleep(2)
        dy2 = self.driver.find_element(By.XPATH,
                                       '/html/body/div[1]/div/section/section/main/h2').text
        self.assertEqual('添加客户', dy2)
        po.send_name()
        po.click_tj()
        # 确定弹窗
        po.accept_alert()

    def test_user_03(self):
        po = Page3(self.driver)
        po.open_url('http://localhost:8081/')
        time.sleep(2)
        po.click_user()
        time.sleep(2)
        dy1 = self.driver.find_element(By.XPATH, '/html/body/div[1]/div/section/section/main/h2').text
        self.assertIn('客户列表', dy1)
        po.click_fenye()
        time.sleep(1)
        # 点击删除按钮
        po.click_del()
        # 取消删除
        text_info = po.dismiss_alert()
        self.assertIn('您确定要删除吗', text_info)




if __name__ == '__main__':
    unittest.main()






